import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QTextEdit
from PyQt5 import QtCore

picture_type = [".jpg", ".png", ".jpeg", ".bmp", ".gif"]
ui_size = {
    "360p": (640, 360),
    "480p": (854, 480),
    "720p": (1280, 720),
    "1080p": (1920, 1080),
}


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
        self.ui_size_key = "360p"

    def initUI(self):
        # 创建用于输出日志的文本框
        self.log_textedit = QTextEdit(self)
        self.log_textedit.setReadOnly(True)

        # 创建按钮
        self.btn1 = QPushButton("360p", self)
        self.btn2 = QPushButton("480p", self)
        self.btn3 = QPushButton("720p", self)

        # 连接按钮的点击信号到对应的槽函数
        self.btn1.clicked.connect(self.btn1_clicked)
        self.btn2.clicked.connect(self.btn2_clicked)
        self.btn3.clicked.connect(self.btn3_clicked)

        self.h_layout = QHBoxLayout()
        self.h_layout.addWidget(self.btn1)
        self.h_layout.addWidget(self.btn2)
        self.h_layout.addWidget(self.btn3)
        self.adjust_ui_layout("360p")

        self.show()

    def btn1_clicked(self):
        self.log_textedit.append("按钮360被点击了")
        self.adjust_ui_layout("360p")

    def btn2_clicked(self):
        self.log_textedit.append("按钮480被点击了")
        self.adjust_ui_layout("480p")

    def btn3_clicked(self):
        self.log_textedit.append("按钮720被点击了")
        self.adjust_ui_layout("720p")

    def adjust_ui_layout(self, ui_size_key):
        global ui_size
        width, height = ui_size[ui_size_key]
        self.log_textedit.setGeometry(0, 0, width, height - 100)
        self.h_layout.setGeometry(QtCore.QRect(0, height - 100, width, 100))
        self.resize(width, height)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
